package hacker_rank.nov13;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class PowerOfLargeNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int T = Integer.parseInt(br.readLine());
		for (int i = 0; i < T; i++) {
			String[] tmp = br.readLine().split(" ");
			solve(tmp[0], tmp[1]);
		}
	}

	private static void solve(String A, String B) {
		BigInteger b1 = new BigInteger(A);
		BigInteger b2 = new BigInteger(B);

		BigInteger res = b1.modPow(b2, BigInteger.valueOf(1000000007));
		System.out.println(res);
	}

}
